//
//  TPRootViewController.m
//  TravelProject
//
//  Created by lanou3g on 15/11/23.
//  Copyright © 2015年 韩婷婷. All rights reserved.
//

#import "TPRootViewController.h"


@interface TPRootViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentControl;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;


@end

@implementation TPRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.scrollView.delegate = self;
    [self setupSegmentControl];
    [self CreatSegmentControl];
   
    // Do any additional setup after loading the view from its nib.
}
- (void)setupSegmentControl{
    self.segmentControl.tintColor = [UIColor clearColor];
    NSDictionary *selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName: [UIColor whiteColor]};
    [self.segmentControl setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];
    NSDictionary *unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],
                                               NSForegroundColorAttributeName: [UIColor lightTextColor]};
    [self.segmentControl setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
}
-(void)CreatSegmentControl{

 [self.segmentControl addTarget:self action:@selector(changeViewAction:) forControlEvents:UIControlEventValueChanged];
}
-(void)changeViewAction:(UISegmentedControl *)sender{
    switch (sender.selectedSegmentIndex) {
        case 0:
            self.scrollView.contentOffset = CGPointMake(0, 0);
            break;
        case 1:
            self.scrollView.contentOffset = CGPointMake(CGRectGetWidth(self.view.frame), 0);
            break;
        default:
            break;
    }
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.segmentControl.selectedSegmentIndex = self.scrollView.contentOffset.x/CGRectGetWidth(self.view.frame);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
